#!/usr/local/bin/lua

local worker = require('worker')
if not worker then
	print('require worker fail')
	os.exit(-1)
end

local thr, err = worker.new()
if not thr then
	print('err:', err)
	os.exit(-1)
end

function hello(str)
	print('hello', str)
	worker.sleep(1)
end

local work1 = {func = hello, args = {'linux', 'yewenhao'}}
local ret, err = thr:add_tail(work1)
if err then
	print('add fail:', err)
end

for i = 1, 100 do
	local work = {func = hello, args = i}
	thr:add_tail(work)
end

print('waiting...')
while true do
	local nums = #thr
	print('nums:', nums)
	if nums > 0 then
		worker.sleep(3)
	else
		break
	end
end
print('done')
